package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Comment;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface CommentMapper extends Mapper<Comment> {

    /**
     * 获取每天的评论数
     */
    @Select("SELECT count(uid) FROM t_comment where create_time BETWEEN #{startTime} and #{endTime} ")
    Integer getCommentCount4Day(@Param("startTime") String startTime, @Param("endTime") String endTime);


    //获取用户点赞的信息
    @Select("select * from t_comment where TYPE ='1'")
    @Results({@Result(column = "user_uid", property = "userUid"),
            @Result(column = "to_uid", property = "toUid"),
            @Result(column = "to_user_uid", property = "toUserUid"),
            @Result(column = "blog_uid", property = "blogUid"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "create_by_uid", property = "createByUid"),
            @Result(column = "update_by_uid", property = "updateByUid"),
            @Result(column = "first_comment_uid", property = "firstCommentUid"),
            @Result(column = "is_publish", property = "isPublish"),
            @Result(column = "create_time", property = "createTime")})
    Page<Comment> getPraiseListByUser();

    //关闭评论
    @Update("update t_user set start_email_notification = 0 where uid=#{userUiD}")
    int closeConment(@Param("userUiD") String userUiD);

    //根据bloguid查询博客点赞数
    @Select("select count(uid) from t_comment where blog_uid=#{blog_uid} and TYPE='1'")
    int getBlogPraiseCountByUid(@Param("blog_uid") String blog_uid);

    @Select("select * from t_comment where blog_uid =#{blogUid} and user_uid=#{userUid}")
    @Results({@Result(column = "user_uid", property = "userUid"),
            @Result(column = "to_uid", property = "toUid"),
            @Result(column = "to_user_uid", property = "toUserUid"),
            @Result(column = "blog_uid", property = "blogUid"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "first_comment_uid", property = "firstCommentUid"),})
    List<Comment> getComment(@Param("blogUid") String blogUid, @Param("userUid") String userUid);
}
